import React, { useState } from 'react'
import {message} from 'antd';
import './index.scss'

import { useStore } from '../../mobx'
import {supabase} from '../../utils'
import Mimicryinput from '../../components/Mimicryinput';
import { LockOutlined, UserOutlined } from '@ant-design/icons';
import Loading from '../../components/Loading';
import dayjs from 'dayjs';
export default function Register() {
  const [loading,setloading]=useState(false)
    async function onFinish(value){
      setloading(true)
        console.log(value)
        let { data, error } = await supabase
      .from('user')
          .insert([
            { ...value, time: dayjs().format('YYYY-MM-DD HH:mm') }
      ])
      if(data!==null){
        setloading(false)
          message.success('注册成功',[1])
          window.history.go(-1)
      }else{
        setloading(false)
          message.error('注册失败',[2])
      }
    // console.log(test);
    }
    
  return (
    <div className='register'>
        {/* <Inputs submit='注册' onFinish={onFinish}/> */}
        <Mimicryinput icon1={<UserOutlined /> } icon2={<LockOutlined/>} text='注册' register={true} onFinish={onFinish}/>
      
      {loading?<Loading/>:''}
    </div>
  )
}
